class socketIONetMananger {

private isConnecteed:boolean;
  public constructor() {
       
    }

    private static instance: socketIONetMananger;
    public static getInstance(): socketIONetMananger {
        if(this.instance == null) {
            this.instance = new socketIONetMananger();
        }
        return this.instance;
    }


	public static test: boolean = false;
   // private  _root_url: string="172.16.19.66";
	private  _root_url: string="172.16.19.59";//"127.0.0.1";
    private _root_url_port:string=":3011";
    private webSocket:egret.WebSocket;
    private socket;
	//CONCNET SERVER
	public connect():void {    
		if(this._root_url===null)
		{
          console.error("未设置连接HOST IP");    
		  return;
		}
	
		if(this.isConnecteed===true)
		{
			console.error("服务器已经连接");    
			return;
		}
	   this.socket = io.connect(this._root_url+this._root_url_port,{query:"type=" + "player"});
       this.receiveMessage();
	}
    // public sendMessage(type:string,msg:any):void {
    //     this.socket.emit(type, msg);
    // }
    private receiveMessage()
    {
        // this.socket.on('loginsucceed',function(data){
        //     LoginMain.LoginBackMess=data=="true"?0:1;
        // });
        // this.socket.on('news', function (data) { });

        // this.socket.on('playerJoin', function (data) { });

        // this.socket.on('gameSetup', function (data)
        // {
        //      var screenDate={
		//     "screenWidth":gameMap.getInstance().canvas_Width,
        //     "screenHeight":gameMap.getInstance().canvas_Height
        //      }
        //        StoryLogic.getInstance().openStory();
        //      //socketIONetMananger.getInstance().sendMessage('windowResized',JSON.stringify(screenDate));
        // });

        // this.socket.on('welcome', function (data)
        //  {

           
		//      var player={
		// 	    "name":gameGlobal.global.playerName,
		// 	     "id": gameMap.getInstance().player.id,
        //          "x":gameMap.getInstance().player.x,
        //          "y":gameMap.getInstance().player.y,
		// 	     "screenWidth":gameMap.getInstance().canvas_Width,
		//       	"screenHeight":gameMap.getInstance().canvas_Height,
		// 	    "target":gameMap.target
		//       }
		//    //socketIONetMananger.getInstance().sendMessage("",JSON.stringify(player));
      
        //  });

        // this.socket.on('serverTellPlayerMove', function (userData, foodsList, massList, virusList) 
        //  {
        //     gameGlobal.global.gameStart=true;
        //     gameGlobal.global.died=false;
        //     var useData={
        //        "userData":userData,
        //       // "foodsList":foodsList,
        //        "lineList":massList,
        //        //"virusList":virusList,
        //      };
        //     gameMap.getInstance().messageHandle(useData);}
        // );

        //  this.socket.on('RIP',function(){
        //    gameMap.getInstance().GameAgain();
        //    gameGlobal.global.gameStart=false;
        //    gameGlobal.global.died=true;
        //    gameGlobal.global.watingAgain=true;
        // });
    }
}